package com.itheima.dubbo.web;

import com.itheima.dubbo.UserInterface;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
public class UserController  {


    // 远程调用
//    @DubboReference(timeout = 5000,version = "2.0.0")
    @DubboReference(check = false)
    private UserInterface userInterface;


    @GetMapping("hello")
    public String hello(String username) {

        RpcContext.getContext().setAttachment("username", "121");
        return userInterface.hello(username);

    }

    @GetMapping("findUser")
    public User findUser(String username) {
        return userInterface.findUser(new User(username, 1));
    }

}
